package interview;

import java.util.Scanner;

public class Demo3 {
    public static volatile int i = 0;
    public static Object o = new Object();
    public static void main(String[] args) throws InterruptedException {
        Thread t1 = new Thread(new Runnable() {
            @Override
            public void run() {
                for (int j = 0; j < 50000; j++) {
                    synchronized (o) {
                        i++;
                    }
                }
            }
        });
        Thread t2 = new Thread(new Runnable() {
            @Override
            public void run() {
                for (int j = 0; j < 50000; j++) {
                    synchronized (o) {
                        i++;
                    }
                }
            }
        });
        t1.start();
        t2.start();
        t1.join();
        t2.join();
        System.out.println(i);
    }
}
